
package com.ibeeking.found.report.rest.controller.v1;

import com.ibeeking.found.report.rest.service.IBaseService;
import com.ibeeking.found.report.rest.service.IReportShareService;
import com.ibeeking.found.report.rest.service.util.ReportUtils;
import com.ibeeking.found.report.service.common.dos.ReportShareDO;
import com.ibeeking.found.report.service.common.param.ReportShareParam;
import com.ibeeking.found.report.service.common.po.ResponseBean;
import com.ibeeking.found.report.service.common.query.ReportSharePageQuery;
import com.ibeeking.found.report.service.common.vo.ReportShareVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.bean.BeanUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author Raod
 * @desc 报表分享 controller
 * @date 2021-08-18 13:37:26.663
 **/
@RestController
@RequestMapping("/reportShare/v1")
public class DmpReportShareController extends DmpBaseController<ReportSharePageQuery, ReportShareDO, ReportShareVO> {

    @Resource
    private IReportShareService reportShareServiceImpl;

    @Override
    public IBaseService<ReportSharePageQuery, ReportShareDO> getService() {
        return reportShareServiceImpl;
    }

    @Override
    public ReportShareDO getEntity() {
        return new ReportShareDO();
    }

    @Override
    public ReportShareVO getDTO() {
        return new ReportShareVO();
    }


    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询报表")
    @GetMapping({"/{id}"})
    public ResponseBean detail(@PathVariable("id") Long id) {
        this.logger.info("{}根据ID查询服务开始，id为：{}", this.getClass().getSimpleName(), id);
        ReportShareDO result = reportShareServiceImpl.getDetail(id);
        ReportShareVO dto = BeanUtil.convertBean(result, ReportShareVO.class);
//        ReportBeanUtils.copyAndFormatter(result, dto);
        ResponseBean responseBean = this.responseSuccessWithData(this.resultDtoHandle(dto));
        this.logger.info("{}根据ID查询结束，结果：{}", this.getClass().getSimpleName(), ReportUtils.toJSONString(responseBean));
        return responseBean;
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询报表")
    @GetMapping({"/detailByCode"})
    public ResponseBean detailByCode(@RequestParam("shareCode") String shareCode) {
        return ResponseBean.builder().data(reportShareServiceImpl.detailByCode(shareCode)).build();
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "分享报表")
    @PostMapping({"/shareDelay"})
    public ResponseBean shareDelay(@RequestBody ReportShareParam dto) {
        reportShareServiceImpl.shareDelay(dto);
        return ResponseBean.builder().build();
    }

}
